Skip to content

feat(cli): add meta verify --uuid-values pre-upgrade scan - #693

Merged
dmealing merged 7 commits into
mainfrom
fm/mo-uuid-prescan
Dec 3, 2026
Merged

dmealing merged 7 commits into
mainfrom
fm/mo-uuid-prescan

Conversation

@dmealing

@dmealing dmealing commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Adds meta verify --uuid-values (new cli/src/lib/uuid-values-check.ts, wired in commands/verify.ts, index.ts, lib/args.ts). It is read-only and runs against SQLite, libSQL, Postgres, or D1 (--dialect d1). It walks every field.uuid place in every stored table, including JSON-stored value objects, lists, and maps. Each place gets a status (scanned, native, missing, unreadable). For each place it reports the count of non-canonical 8-4-4-4-12 values and up to five samples, and it exits 1 when it finds any or when a place could not be read.
  • Column layout comes from migrate-ts storedTablesOf (expected-schema.ts, exported from index.ts), so the scan and meta migrate agree on which column holds which field. introspect/d1.ts and metadata/src/loader/validation-passes.ts change to support that enumeration.
  • Documents the check in docs/features/migrations-and-drift.md and docs/features/cli.md, and adds a CHANGELOG entry plus a pointer from the 1.3.0 uuid write-check note. Adds unit and integration tests (verify-uuid-values.test.ts, uuid-values-scan.test.ts) and CLI snapshot and args updates.

Gate: this took two no-mistakes runs. The first ran three review fix rounds and hit the review round cap. The second fixed the two findings that cap had left as notes: a TPH subtype that redeclares a base field, and a --db with no URL scheme.

Validation

Risk Assessment

✅ Low: The increment closes the two prior findings: base-versus-subtype TPH redeclaration and the uncaught scheme-less --db error. Traced row-set algebra, SQL filters and migrate DDL invariance all hold, and the new test pins migrate's column list.

Testing

Built a disposable SQLite project under scratch, ran the real CLI against it. Non-canonical 'mbr1' row: exit 1, finding names members.id with sample 'mbr1' and the 1.3 write-refusal explanation. Clean DB: exit 0 with 'every stored value is canonical'. Mistyped --db path: exit 1 with 'incomplete ... cannot say every stored value is canonical' instead of a green verdict, which fixes the nothing-scanned false green. Side effect: the mistyped path still created an empty stray DB file, an inherent property of the SQLite open. D1-specific behavior (short GLOB pattern, --dialect d1 on a long constraint name) was not driven live. Broad regression is the baseline ci-local run, which passed.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Non-canonical stored uuid in SQLite is reported before upgrade (local SQLite, synthetic 'mbr1' row) ✅ pass live CLI run: bun .../cli/bin/meta.ts verify --uuid-values --db file:app.db; output lists members.id with sample mbr1, exit 1
Clean canonical data passes the scan (local SQLite, synthetic canonical uuid) ✅ pass live CLI run on file:clean.db: 'every stored field.uuid value is canonical', exit 0
Mistyped --db path does not produce a false green (adversarial) ✅ pass live CLI run on file:app.dbb: NOT READ table not in this database, verdict incomplete, exit 1
D1 scan works with the GLOB pattern limit (--dialect d1) ⏸️ untested no Needs a local D1 runtime (miniflare) to execute the generated queries. Not run here; the fix was only checked by reading the code. Run the D1 integration lane or a local wrangler/miniflare D1 to prove…
Evidence: uuid-values non-canonical SQLite run transcript
meta verify --uuid-values — 1 field.uuid place(s) in file:app.db:
members.id (Member.id): 1 value(s) not a canonical uuid, e.g. "mbr1"
exitCode: 1 (summary: 1 of 2 gate(s) failed (uuid-values))

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - resolved: every finding below is fixed on this branch

♻️ Reviewed only the branch's changes since run 01M8WPGR9TJZ54DQHGP5B106RE approved; the rest of the branch carries that approval.

Findings carried from run 01M8WPGR9TJZ54DQHGP5B106RE. Each is fixed on this branch: the sibling-subtype case in 5e5c0d8, and the base-field redeclaration and the scheme-less --db in cd80b61. Each fix has a test that fails without it. The last item is a comment-only fix the review applied inline.

  • ⚠️ server/typescript/packages/migrate-ts/src/expected-schema.ts:423 - False all-clear when sibling TPH subtypes share a column but declare different field nodes. storedFieldsOf keeps only the first field per column (if (existing.has(column)) continue), and uuidPlacesOf walks only that field. Example: base Party; subtype Auto has field.object detail @objectRef AutoDetail (strings only); subtype Home has field.object detail @objectRef HomeDetail (ownerId is field.uuid). Only Auto.detail survives, so parties.detail $.ownerId is never a place. A stored {"ownerId":"mbr1"} on a Home row then yields "every stored field.uuid value is canonical", although Home's write schema refuses it. The same happens with Auto.externalId as field.string and Home.externalId as field.uuid. migrate already supports sibling nodes that differ on one column (see the CHECK grouping near line 1128). Round 2 introduced this: the gate head 14b5857 walked each subtype object's own effective fields, so it read both. Sites: expected-schema.ts:423 (dedupe drops the sibling node); uuid-values-check.ts:123 (consumes one field per column); the "every place the model types field.uuid" claims in CHANGELOG.md and docs/features/migrations-and-drift.md. Fix: keep migrate's column list unchanged, but have StoredField also expose the other distinct sibling field nodes with their subtypes. Walk all of them and merge identical places. Where sibling types differ (string and uuid on one column), restrict the uuid read to rows carrying the declaring subtypes' discriminator values, so the string sibling's rows are not reported. Add this sibling case to the tests.

  • ⚠️ server/typescript/packages/migrate-ts/src/expected-schema.ts:435 - False all-clear: a TPH subtype that redeclares a base field is never scanned. storedFieldsOf skips every subtype field whose name is in baseFieldNames, even when the subtype's effective field is a different node with a different type. Reproduced on this head: base Party has field.object detail @objectRef: A (no uuid) and field.string ref; subtype Home overrides them with detail @objectRef: B (B has field.uuid ownerId) and field.uuid ref. The model loads with no errors. The generated HomeInsertSchema and HomeUpdateSchema enforce the uuid regex on ref and use BInsertSchema for detail. uuidPlacesOf returns [], so --uuid-values prints 'declares no stored field.uuid; nothing to scan' and exits 0 while Home rows may hold "mbr1". The round 3 fix covered sibling-versus-sibling differences and left base-versus-subtype. Fix: in storedTablesOf's layout, also emit an entry (with subtypes) when a subtype's node for a base field or base column differs from the base's node, and keep migrate's columns and DDL unchanged (buildTable already skips a subtype entry whose column exists). Sibling sites of the same rule: expected-schema.ts:439 (baseColumns.has(column) drops a subtype field that shares a base column); uuid-values-check.ts:145-150 (carriers counts only subtype entries, so a uuid place held only by an overriding subtype would get no rows restriction and would report base and other-subtype strings; it must be restricted whenever a base entry occupies the column without a uuid at that path); the reverse case, a base uuid place overridden by a non-uuid subtype field (uuid-values-check.ts:119), currently reads that subtype's rows and reports its strings as findings.

  • ℹ️ server/typescript/packages/cli/src/commands/verify.ts:1711 - inferDialect(flags.db) runs outside any try in runUuidValuesVerify. meta verify --uuid-values --db ./app.db (no URL scheme) therefore throws out of verifyCommand, and bin/meta.ts does not catch it: the user gets an uncaught error, and --format json emits no payload or errors[] entry. Move the dialect inference into a try that sets uuidValuesRunError, logs it and returns 1, as the connection failure below does.

  • ℹ️ server/typescript/packages/migrate-ts/src/expected-schema.ts:388 - Inline fix. The storedFieldsOf docstring and the TPH-block comment still said a column the base already stores is 'not re-emitted'. The change now appends overridesBase entries for subtype redeclarations, and buildTable skips them. Both comments were reworded to describe those entries. Comment-only, no behaviour change.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Non-canonical stored uuid in SQLite is reported before upgrade (local SQLite, synthetic 'mbr1' row) ✅ pass live CLI run: bun .../cli/bin/meta.ts verify --uuid-values --db file:app.db; output lists members.id with sample mbr1, exit 1
Clean canonical data passes the scan (local SQLite, synthetic canonical uuid) ✅ pass live CLI run on file:clean.db: 'every stored field.uuid value is canonical', exit 0
Mistyped --db path does not produce a false green (adversarial) ✅ pass live CLI run on file:app.dbb: NOT READ table not in this database, verdict incomplete, exit 1
D1 scan works with the GLOB pattern limit (--dialect d1) ⏸️ untested no Needs a local D1 runtime (miniflare) to execute the generated queries. Not run here; the fix was only checked by reading the code. Run the D1 integration lane or a local wrangler/miniflare D1 to prove…
  • scripts/ci-local.sh --affected --strict-toolchains
  • bun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:app.db (table members with id='mbr1' and one canonical uuid)
  • bun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:clean.db (all canonical)
  • bun server/typescript/packages/cli/bin/meta.ts verify --uuid-values --db file:app.dbb (mistyped path, no matching table)
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains (already passed; not re-run)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

… check refuses

A read-only pre-upgrade check. With --db <url> or --dialect d1, it reads every
field.uuid column (keys, foreign keys, each isArray element) in the governed
tables and lists those holding values that are not canonical 8-4-4-4-12 uuids,
with a count and samples, exiting 1 when any are found. A native Postgres uuid
column is reported as guaranteed and not read. Columns come from the same
schema builder meta migrate uses. Node CLI only, like the other live-database
checks.
…its own rows; scheme-less --db is a run error

A subtype that redeclares a field its base stores put its own node in the base's column, and
the scan only walked the base's node: a uuid redeclaration was never read (a false all-clear),
and a string redeclaration of a base uuid got that subtype's strings reported. storedTablesOf now
records the redeclaration (the base's entry builds the column, so migrate's DDL is unchanged),
and the scan reads each node in the rows that hold it. A --db with no URL scheme now fails the
uuid-values gate with exit 1 and an errors[] entry instead of an uncaught throw.
@dmealing
dmealing merged commit 43b9b8b into main Dec 3, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-uuid-prescan branch December 3, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant